<template>
    <TabGrayEasyCard v-if="isShow" :title="'两书对标'" :isMore="false" @onMore="goDetail(props.permi)" :tabs="card.tabs" :curTab="card.curTab"
        :tabRight="card.tabRight" @onChange="changeTab" :grayCardList="card.grayCardList" :lineText="''" :barText="''"
        :unitText="`单位：${card.unitText}`" :updateText="card.updateText"
        v-btnPermi="{ permi: props.permi, noReport: true, isHiden: true, hideList: props.hideList }">

        <slot>
            <el-table :data="card.tableData" height="100%">
                <el-table-column prop="indexName" label="指标" :align="'left'" show-overflow-tooltip/>
                <el-table-column label="两书目标" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.targetYear) }}
                    </template>
                </el-table-column>
                <el-table-column label="实际" :align="'right'">
                    <template #default="scope">
                        {{ toThousands(scope.row.actualYear) }}
                    </template>
                </el-table-column>
                <el-table-column label="完成率" :align="'right'">
                    <template #default="scope">
                        {{ scope.row.wclYear == '-' ? '-' : toThousands(scope.row.wclYear) + '%' }}
                    </template>
                </el-table-column>
            </el-table>
        </slot>
    </TabGrayEasyCard>
</template>

<script setup>
import TabGrayEasyCard from '@/DbComponents/tabGrayEasyCard'
import { toThousands } from '@/utils/number-util'
import dashBoardApi from '@/api/Manage/Business/dashBoard'
import { ref, reactive, watch, computed } from 'vue'
import { reportLog } from '@/utils/reportLog'

const props = defineProps({
    permi: {
        type: String,
        required: false,
        default: ''
    },
    hideList: {
        type: Array,
        required: false,
    },
    biProjectCode: {
        type: String,
        required: false,
        default: ''
    },
    updateDate: {
        type: String,
        required: false,
        default: ''
    }
})
const card = reactive(
    {
        tabs: [{ label: '按年', value: '年' }],
        curTab: '年',
        tabRight: '',
        // grayCardList: [],
        unitText: '',
        updateText: '',
        tableData: [],
        // startDate: '',
        // endDate: '',
    }
)

const getChartData = () => {
    dashBoardApi.queryHomePageListApi({ biProjectCode: props.biProjectCode }).then((res) => {
        if (res.data.code == 200) {
            card.tabRight = res.data.data[0] ? res.data.data[0].rightUp : '-'
            card.tableData = res.data.data
            card.unitText = res.data.data[0] ? res.data.data[0].valueUnit : '-'
            card.updateText = res.data.data[0] ? res.data.data[0].rightDown : '-'
        }
    }).catch(err => {
        console.log(err)
    });
}

const goDetail = (permi) => {
    reportLog({
        type: 4,
        resourceKey: permi,
    })
}
const changeTab = (value) => {
    console.log(value)
    getChartData()
}

let isShow = ref(false)
const getShow = async () => {
    await dashBoardApi.queryTwoBooksLabApi({ biProjectCode: props.biProjectCode }).then((res) => {
        if (res.data.code == 200) {
            isShow.value = res.data.data.twoBooksLab == 1 ? true : false
        }
    }).catch(err => {
        console.log(err)
    });
}
const init = async () => {
    await getShow()
    isShow.value == true ? getChartData() : ''
}
init()

const biProjectCode = computed(() => {
    return props.biProjectCode
});
watch(biProjectCode, () => {
    init()
}, { deep: true });
</script>

<style scoped lang="scss"></style>
